package cn.conchit.apccontroldemo.graph.canvas;


import cn.conchit.apccontroldemo.graph.cmpt.CGateInCmpt;
import cn.conchit.apccontroldemo.graph.cmpt.CGateOutCmpt;
import cn.conchit.apccontroldemo.graph.cmpt.MpcCmpt;
import cn.conchit.apccontroldemo.graph.cmpt.PythonCmpt;
import cn.conchit.apccontroldemo.graph.exception.DirectGraphException;
import cn.conchit.apccontroldemo.graph.po.Cmpt;

import java.util.HashSet;
import java.util.Iterator;
import java.util.List;

/**
 * @author hetao
 * @version 1.0
 * @description: TODO
 * @date 2023/2/15 10:48
 */
public class App {

    public static void main(String[] args) throws DirectGraphException, CloneNotSupportedException {
        CanvasGraph<CmptVertex, String> directGraph = new CanvasGraph<CmptVertex, String>();

        directGraph.addVertex(new CmptVertex(new Cmpt(1, "111Vertex", "cgatein", "1.0", "cn.conchit.apccontroldemo.graph.cmpt.CGateInCmpt")));
        directGraph.addVertex(new CmptVertex(new Cmpt(2, "222Vertex", "python", "1.0", "cn.conchit.apccontroldemo.graph.cmpt.PythonCmpt")));
        directGraph.addVertex(new CmptVertex(new Cmpt(3, "333Vertex", "python", "1.0", "cn.conchit.apccontroldemo.graph.cmpt.PythonCmpt")));
        directGraph.addVertex(new CmptVertex(new Cmpt(4, "444Vertex", "mpc", "1.0", "cn.conchit.apccontroldemo.graph.cmpt.MpcCmpt")));
        directGraph.addVertex(new CmptVertex(new Cmpt(5, "555Vertex", "python", "1.0", "cn.conchit.apccontroldemo.graph.cmpt.PythonCmpt")));
        directGraph.addVertex(new CmptVertex(new Cmpt(6, "666Vertex", "cgateout", "1.0", "cn.conchit.apccontroldemo.graph.cmpt.CGateOutCmpt")));

        directGraph.addEdge(new Edge<>(1, 2, "1-edge-2"));
        directGraph.addEdge(new Edge<>(1, 3, "1-edge-3"));
        directGraph.addEdge(new Edge<>(1, 4, "1-edge-4"));
        directGraph.addEdge(new Edge<>(2, 5, "2-edge-5"));
        directGraph.addEdge(new Edge<>(3, 5, "3-edge-5"));
        directGraph.addEdge(new Edge<>(4, 6, "4-edge-6"));
        directGraph.addEdge(new Edge<>(5, 6, "5-edge-6"));

//        directGraph.removeEdge(2, 5);
//        directGraph.removeEdge(3, 5);
//        directGraph.removeEdge(5, 6);


        List<HashSet<CmptNode>> seqList =  directGraph.sequence();
        for(int i = 0; i < seqList.size(); i++) {
            HashSet<CmptNode> set = seqList.get(i);
            System.out.println("第"+(i+1)+"批次：");
            Iterator<CmptNode> it = set.iterator();
            while (it.hasNext()) {
                CmptNode node = it.next();
                node.callJob();
            }
         }

    }


}
